package com.hermeneute.fsa;

import java.util.Map;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

public class IncrementalProjectBuilder extends
		org.eclipse.core.resources.IncrementalProjectBuilder {

	public IncrementalProjectBuilder() {
	}

	@Override
	protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
			throws CoreException {
		if (kind == IncrementalProjectBuilder.FULL_BUILD){
			fullBuild(monitor);
		} else {
			IResourceDelta delta = getDelta(getProject());
			if (delta == null) {
				fullBuild(monitor);
			} else {
				incrementalBuild(delta,monitor);
			}
		}
		return null;
	}
	private void fullBuild(IProgressMonitor monitor) {
		System.out.println("full build");
	}
	private void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) {
		System.out.println("incremental build on "+delta);
		try {
			delta.accept(new IResourceDeltaVisitor () {

				public boolean visit(IResourceDelta delta) throws CoreException {
					System.out.println("Changed: "+delta.getResource().getRawLocation());
					return true;
				}
				
			});
		}catch (CoreException e) {
			e.printStackTrace();
		}
	}
}
